package com.gok.seasonmovie.service;

import com.gok.seasonmovie.entity.Comment;
import com.gok.seasonmovie.entity.Movie;
import com.gok.seasonmovie.mapper.CommentMapper;
import com.gok.seasonmovie.mapper.MovieMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
public class MovieService {
    @Autowired
    private MovieMapper movieMapper;

    public List<Movie> findAll() {
        return movieMapper.findAll();
    }

    public List<Movie> getMovieByMid(String id){ return movieMapper.getMovieByMid(id);}

    public List<Movie> searchMovies(String keyword) {
        // 将搜索关键字中的每个字符分开，并插入百分号以实现模糊匹配
        Set<Movie> resultSet = new HashSet<>();

        for (char c : keyword.toCharArray()) {
            List<Movie> movies = movieMapper.searchMovies(String.valueOf(c));
            resultSet.addAll(movies);
        }
        return new ArrayList<>(resultSet);
    }

}